local skel = fk.CreateSkill {
  name = "efengqi__kurou",
}

Fk:loadTranslationTable{
  ["efengqi__kurou"] = "苦肉",
  [":efengqi__kurou"] = "当你受到伤害后，你可以令伤害来源摸两张牌并横置，且其本回合【杀】次数上限改为你此时已损失体力值。",

  ["#efengqi__kurou-ask"] = "苦肉：你可以令 %src 摸两张牌并横置，且【杀】次数上限改为 %arg",
  ["@efengqi__kurou-turn"] = "苦肉",

  ["$efengqi__kurou1"] = "我这把老骨头，不算什么！",
  ["$efengqi__kurou2"] = "为成大业，死不足惜！",
}

skel:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) then
      return data.from and not data.from.dead and not data.from.chained
    end
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askToSkillInvoke(player, { skill_name = skel.name,
     prompt = "#efengqi__kurou-ask:"..data.from.id.."::"..player:getLostHp() }) then
      event:setCostData(self, { tos = {data.from} })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local to = data.from---@type ServerPlayer
    to:drawCards(2, self.name)
    if not to.dead and not to.chained then
      to:setChainState(true)
    end
    if not to.dead then
      room:setPlayerMark(to, "@efengqi__kurou-turn", tostring(player:getLostHp()))
    end
  end,
})

skel:addEffect("targetmod", {
  fix_times_func = function (self, player, skill, scope, card, to)
    if player and skill and scope and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      local mark = player:getMark("@efengqi__kurou-turn")
      if mark ~= 0 then
        return tonumber(mark)
      end
    end
  end,
})

return skel
